#include "core/Spin.h"

void SingleSpinInitialization(cSPIN * spinlist)
{
	int i;
    if(TASK_MODE == 1)
    {
    	for (i = 0; i < NBATH; i++)
    	{
    		spinlist[i].initialize_SingleSample(i, EXT_MAG_FIELD, ABSOLUTE_GAMMA_N[i], INIT_STATES[i]);
    	}
    }
    else
    {
    	for (i = 0; i < NBATH; i++)
    	{
    		spinlist[i].initialize_Ensemble(i, EXT_MAG_FIELD, ABSOLUTE_GAMMA_N[i]);
    	}
    }
}

void cSPIN::initialize_SingleSample(int idx,double mag, double gamma, int state)
{
	int i;

	index       = idx;
	init_state  = state;
	extfield    = mag;

	zeemanenergy =  - mag * gamma * 1E-3;

	//////////////////////////////////////////////////////////////////////////
	//meanfield = 0, for ensemble CCE

	sINT_TENSOR1 dip;

	meanfield.x = 0.;	meanfield.y = 0.;	meanfield.z = 0.;

	for (i = 0; i < NBATH; i ++)
	{
	    dip = calc_dipole_int(idx, i);
	    meanfield.x += dip.zx * INIT_STATES[i] * 0.5;
	    meanfield.y += dip.yz * INIT_STATES[i] * 0.5;
	    meanfield.z += dip.zz * INIT_STATES[i] * 0.5;
	}
	//end of meanfield.
	//////////////////////////////////////////////////////////////////////////


	//////////////////////////////////////////////////////////////////////////
	//set hyperfine field
	hyperfine_field1.x = NE_INT_MAT1[index * 3 + 0];
	hyperfine_field1.y = NE_INT_MAT1[index * 3 + 1];
	hyperfine_field1.z = NE_INT_MAT1[index * 3 + 2];
	hyperfine_field2.x = NE_INT_MAT2[index * 3 + 0];
	hyperfine_field2.y = NE_INT_MAT2[index * 3 + 1];
	hyperfine_field2.z = NE_INT_MAT2[index * 3 + 2];
	//end of setting
	//////////////////////////////////////////////////////////////////////////
}


void cSPIN::initialize_Ensemble(int idx,double mag, double gamma)
{
	index       = idx;
	extfield    = mag;

	zeemanenergy = - mag * gamma * 1E-3;

	//////////////////////////////////////////////////////////////////////////
	//meanfield = 0, for ensemble CCE
	meanfield.x = 0.;	meanfield.y = 0.;	meanfield.z = 0.;
	//end of meanfield.
	//////////////////////////////////////////////////////////////////////////


	//////////////////////////////////////////////////////////////////////////
	//set hyperfine field
	hyperfine_field1.x = NE_INT_MAT1[index * 3 + 0];
	hyperfine_field1.y = NE_INT_MAT1[index * 3 + 1];
	hyperfine_field1.z = NE_INT_MAT1[index * 3 + 2];
	hyperfine_field2.x = NE_INT_MAT2[index * 3 + 0];
	hyperfine_field2.y = NE_INT_MAT2[index * 3 + 1];
	hyperfine_field2.z = NE_INT_MAT2[index * 3 + 2];
	//end of setting
	//////////////////////////////////////////////////////////////////////////
}
